package com.tsingtao.springcloudproject1.service.impl;

import com.tsingtao.springcloudproject1.entity.Project1;
import com.tsingtao.springcloudproject1.entity.Project2;
import com.tsingtao.springcloudproject1.feign.Project2FeignClient;
import com.tsingtao.springcloudproject1.mapper.Project1Mapper;
import com.tsingtao.springcloudproject1.service.TestSeataService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestSeataServiceImpl implements TestSeataService {

    @Autowired
    private Project1Mapper project1Mapper;

    @Autowired
    private Project2FeignClient project2FeignClient;


    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    @Transactional(propagation = Propagation.REQUIRED)
    public int insert(Project1 project1) {
        Project2 project2 = Project2.builder().name(project1.getName()).build();
        project2FeignClient.insert(project2);
        int insert = project1Mapper.insert(project1);
        int i = 1 / 0;
        return insert;
    }
}
